package cn.kbyue.ormdemo.controller;

import cn.kbyue.ormdemo.entity.Simple;
import cn.kbyue.ormdemo.service.ISimpleService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xlang
 * @date 2023/4/12 14:21
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/simple")
public class SimpleController {

    private final ISimpleService simpleService;

    @GetMapping("/list")
    public ResponseEntity<List<Simple>> list() {
        return ResponseEntity.ok(new Simple().selectAll());
    }

    @GetMapping("/query")
    public ResponseEntity<List<Simple>> query(@RequestParam("name") String name) {
        return ResponseEntity.ok(simpleService.queryList(name));
    }

    @GetMapping("/{id}")
    public ResponseEntity<Simple> get(@PathVariable("id") Long id) {
        return ResponseEntity.ok(simpleService.getById(id));
    }

}
